package com.twu.biblioteca.Models;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Aru
 * Date: 5/24/13
 * Time: 1:02 PM
 * To change this template use File | Settings | File Templates.
 */
public class UserList
{
    public HashMap<String,User> userCredentials = new HashMap<String, User>();

    //default initialization
    public UserList()
    {
        userCredentials.put("111-1111", new User("111-1111","12345","abcd@wohoo.com",false));
        userCredentials.put("111-1112", new User("111-1112","12345","efgh@wohoo.com",Boolean.FALSE));
        userCredentials.put("111-1113", new User("111-1113","12345","ijkl@wohoo.com",false));
    }

    public void addUser(User user)
    {
        userCredentials.put(user.userName,user);
    }

    public User getUser(String user)
    {
        if(userCredentials.containsKey(user))
            return userCredentials.get(user);
        else
            return null;
    }

    public Boolean validatePassword(String userName,String password)
    {
        User user = userCredentials.get(userName);
        Boolean isValid = user.validatePassword(password);
        return isValid;
    }

    public User getCurrentActiveUser()
    {
       User activeUser = null;
       for (String key : userCredentials.keySet())
       {
         User user = userCredentials.get(key);
                 if(user.getLoggedIn())
                 {
                     activeUser = user;
                     break;
                 }
       }
        return activeUser;
    }

    public void logOutAll()
    {
        for (String key : userCredentials.keySet())
        {
            User user = userCredentials.get(key);
            user.setLoggedIn(false);
        }
    }
}

